#!/usr/bin/env node

// const { time } = require('console');
const {EventEmitter} = require('./05-event');

class Dog extends EventEmitter{
    //公有数据
    constructor(name,energy){
        super();
        this.#name =name;
        this.#energy=energy;
        this.#start();
        // let timer = setInterval(() => {
        //     this.emit('bark');
        //     this.#energy--;
        //     if (this.#energy === 0) {
        //         clearInterval(timer);
        //     }
        // }, 1000);
    }

    get name(){ return this.#name;}
    get energy(){return this.#energy;}
    set energy(e){
        this.#energy = e;
        this.#start();
    }
    //私有数据
    #start(){
        let timer = setInterval(() => {
            this.emit('bark');
            this.#energy--;
            if (this.#energy <= 0) {
                clearInterval(timer);
            }
        }, 1000);
    }
    #name = '';
    #energy = 0;
};
module.exports = Dog;